//
// DotNetNuke - http://www.dotnetnuke.com
// Copyright (c) 2002-2010
// by Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
//

using System.Web;
using System.Web.UI.WebControls;
namespace DotNetNuke.UI.WebControls
{
	public class ImageCommandColumn : System.Web.UI.WebControls.TemplateColumn
	{
		private string mCommandName;
		private ImageCommandColumnEditMode mEditMode = ImageCommandColumnEditMode.Command;
		private string mImageURL;
		private string mKeyField;
		private string mNavigateURL;
		private string mNavigateURLFormatString;
		private string mOnClickJS;
		private bool mShowImage = true;
		private string mText;
		private bool mVisible = true;
		private string mVisibleField;
		public string CommandName
		{
			get { return mCommandName; }
			set { mCommandName = value; }
		}
		public ImageCommandColumnEditMode EditMode
		{
			get { return mEditMode; }
			set { mEditMode = value; }
		}
		public string ImageURL
		{
			get { return mImageURL; }
			set { mImageURL = value; }
		}
		public string KeyField
		{
			get { return mKeyField; }
			set { mKeyField = value; }
		}
		public string NavigateURL
		{
			get { return mNavigateURL; }
			set { mNavigateURL = value; }
		}
		public string NavigateURLFormatString
		{
			get { return mNavigateURLFormatString; }
			set { mNavigateURLFormatString = value; }
		}
		public string OnClickJS
		{
			get { return mOnClickJS; }
			set { mOnClickJS = value; }
		}
		public bool ShowImage
		{
			get { return mShowImage; }
			set { mShowImage = value; }
		}
		public string Text
		{
			get { return mText; }
			set { mText = value; }
		}
		public string VisibleField
		{
			get { return mVisibleField; }
			set { mVisibleField = value; }
		}
		private ImageCommandColumnTemplate CreateTemplate(ListItemType type)
		{
			bool isDesignMode = false;
			if (HttpContext.Current == null)
			{
				isDesignMode = true;
			}
			ImageCommandColumnTemplate template = new ImageCommandColumnTemplate(type);
			if (type != ListItemType.Header)
			{
				template.ImageURL = ImageURL;
				if (!isDesignMode)
				{
					template.CommandName = CommandName;
					template.VisibleField = VisibleField;
					template.KeyField = KeyField;
				}
			}
			template.EditMode = EditMode;
			template.NavigateURL = NavigateURL;
			template.NavigateURLFormatString = NavigateURLFormatString;
			template.OnClickJS = OnClickJS;
			template.ShowImage = ShowImage;
			template.Visible = Visible;
			if (type == ListItemType.Header)
			{
				template.Text = HeaderText;
			}
			else
			{
				template.Text = Text;
			}
			template.DesignMode = isDesignMode;
			return template;
		}
		public override void Initialize()
		{
			this.ItemTemplate = CreateTemplate(ListItemType.Item);
			this.EditItemTemplate = CreateTemplate(ListItemType.EditItem);
			this.HeaderTemplate = CreateTemplate(ListItemType.Header);
			if (HttpContext.Current == null)
			{
				this.HeaderStyle.Font.Names = new string[] { "Tahoma, Verdana, Arial" };
				this.HeaderStyle.Font.Size = new FontUnit("10pt");
				this.HeaderStyle.Font.Bold = true;
			}
			this.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
			this.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
		}
	}
}
